using GGPhysics;
using UnityEngine;

public class GGPLineCollider : GGPShape
{
	public LineShape line;

	public override Shape shape
	{
		get
		{
			return line;
		}
	}

	public Vector3 TransformLinePoint(Vector3 linePoint)
	{
		Vector3 vector = base.transform.TransformPoint(line.point1);
		return base.transform.InverseTransformDirection(vector - base.transform.position);
	}

	public override Shape CreateShapeForEngine()
	{
		LineShape lineShape = new LineShape();
		Vector3 vector = base.transform.TransformPoint(line.point1);
		lineShape.point1 = base.transform.InverseTransformDirection(vector - base.transform.position);
		Vector3 vector2 = base.transform.TransformPoint(line.point2);
		lineShape.point2 = base.transform.InverseTransformDirection(vector2 - base.transform.position);
		return lineShape;
	}

	private void OnDrawGizmos()
	{
		Color color = Gizmos.color;
		Gizmos.color = Color.green;
		Vector3 from = base.transform.TransformPoint(line.point1);
		Vector3 to = base.transform.TransformPoint(line.point2);
		Gizmos.DrawLine(from, to);
		Gizmos.color = color;
	}

	public void SetParamsFromMesh()
	{
		MeshRenderer component = GetComponent<MeshRenderer>();
		if (!(component == null))
		{
			Bounds bounds = component.bounds;
			Vector3 vector = base.transform.InverseTransformDirection(bounds.extents);
			Vector3 vector2 = base.transform.InverseTransformDirection(-bounds.extents);
			Vector3 vector3 = new Vector3(Mathf.Abs(vector.x), Mathf.Abs(vector.y), Mathf.Abs(vector.z));
			if (vector3.x >= vector3.y && vector3.x >= vector3.z)
			{
				vector = Vector3.Scale(vector, new Vector3(1f, 0f, 0f));
				vector2 = Vector3.Scale(vector2, new Vector3(1f, 0f, 0f));
			}
			else if (vector3.y >= vector3.x && vector3.y >= vector3.z)
			{
				vector = Vector3.Scale(vector, new Vector3(0f, 1f, 0f));
				vector2 = Vector3.Scale(vector2, new Vector3(0f, 1f, 0f));
			}
			else if (vector3.z >= vector3.x && vector3.z >= vector3.y)
			{
				vector = Vector3.Scale(vector, new Vector3(0f, 0f, 1f));
				vector2 = Vector3.Scale(vector2, new Vector3(0f, 0f, 1f));
			}
			line.point1 = vector2;
			line.point2 = vector;
		}
	}
}
